import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  // / 登录注册页面
  {
    path: '/',
    component: () => import('@/views/index/')
  },
  // 首页
  {
    path: '/layout',
    redirect: '/welcome',
    component: () => import('@/views/layout'),
    children: [
      { path: '/welcome',
        name: '首页',
        component: () => import('@/views/home')
      }
    ]
  },
  // 排课管理
  {
    path: '/schedule/',
    name: '排课管理',
    redirect: '/schedule/preview',
    component: () => import('@/views/layout'),
    children: [
      {
        path: '/schedule/preview',
        name: '排课预览',
        component: () => import('@/views/schedule')
      },
      {
        path: '/schedule/add/:semesterId/:weekNum/:week/:time',
        name: '添加排课',
        component: () => import('@/views/schedule/form')
      },
      {
        path: '/schedule/edit/:scheduleId',
        name: '排课编辑',
        component: () => import('@/views/schedule/form')
      }
    ]
  },
  // 权限管理
  {
    path: '/right/',
    name: '权限管理',
    redirect: '/right/preview',
    component: () => import('@/views/layout'),
    children: [
      {
        path: '/right/preview',
        name: '权限预览',
        component: () => import('@/views/right')
      }
    ]
  },
  // 学期管理
  {
    path: '/semester/',
    name: '学期管理',
    redirect: '/semester/preview',
    component: () => import('@/views/layout'),
    children: [
      {
        path: '/semester/preview',
        name: '学期预览',
        component: () => import('@/views/semester')
      },
      {
        path: '/semester/add',
        name: '添加学期',
        component: () => import('@/views/semester/form')
      },
      {
        path: '/semester/edit/:semesterId',
        name: '修改学期',
        component: () => import('@/views/semester/form')
      }
    ]
  },
  // 角色管理
  {
    path: '/role/',
    name: '角色管理',
    redirect: '/role/preview',
    component: () => import('@/views/layout'),
    children: [
      {
        path: '/role/preview',
        name: '角色预览',
        component: () => import('@/views/role')
      },
      {
        path: '/role/add',
        name: '添加角色',
        component: () => import('@/views/role/form')
      }
    ]
  },
  // 字典管理
  {
    path: '/dictionary/',
    name: '字典管理',
    redirect: '/semester/preview',
    component: () => import('@/views/layout'),
    children: [
      {
        path: '/dictionary/major/edit',
        name: '专业编辑',
        component: () => import('@/views/dictionary/major')
      },
      {
        path: '/dictionary/major/add',
        name: '添加专业',
        component: () => import('@/views/dictionary/major/form')
      }
    ]
  },
  // 教师管理
  {
    path: '/teacher/',
    name: '教师管理',
    redirect: '/teacher/preview',
    component: () => import('@/views/layout'),
    children: [
      {
        path: '/teacher/preview',
        name: '教师预览',
        component: () => import('@/views/teacher')
      },
      {
        path: '/teacher/add',
        name: '添加教师',
        component: () => import('@/views/teacher/form')
      },
      {
        path: '/teacher/edit/:teacherId',
        name: '修改教师',
        component: () => import('@/views/teacher/form')
      }
    ]
  },
  // 404
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/404')
  },
  { path: '*',
    redirect: '/404',
    hidden: true
  }

]

function getAbsolutePath() {
  const path = location.pathname
  return path.substring(0, path.lastIndexOf('/') + 1)
}
const router = new VueRouter({
  // mode: 'history',
  base: getAbsolutePath(),
  routes
})

export default router
